package com.lhd.hms;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lhd.hms.face.FaceAnalyzerActivity;
import com.lhd.hms.location.LocationActivity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView mRvGallery;
    List<String> titles = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initItems();
        initView();
    }

    private void initItems() {
        titles.add("账户服务");
        titles.add("人脸检测");
        titles.add("文字识别");
        titles.add("文档矫正");
        titles.add("位置服务");
        titles.add("IAP");
        titles.add("消息推送");
    }

    private void initView() {
        mRvGallery = (RecyclerView) findViewById(R.id.rv_gallery);
        mRvGallery.setLayoutManager(new GridLayoutManager(this,4));
        mRvGallery.setAdapter(new MyAdapter());


    }

    public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

        @NonNull
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            View view = layoutInflater.inflate(R.layout.recycler_list_item, null);
            return new MyViewHolder(view);
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position) {
            String title = titles.get(position);
            holder.mTvTitle.setText(title);
            holder.mIvIcon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    switch (position){
                        case 0:
                            break;
                        case 1:
                        {
                            Intent intent = new Intent(MainActivity.this, FaceAnalyzerActivity.class);
                            startActivity(intent);
                            //人脸检测

                        }
                            break;
                        case 4:
                        {
                            Intent intent = new Intent(MainActivity.this, LocationActivity.class);
                            startActivity(intent);
                        }
                            break;
                    }
                }
            });
        }

        @Override
        public int getItemCount() {
            return titles.size();
        }

        class MyViewHolder extends RecyclerView.ViewHolder {
            ImageView mIvIcon;
            TextView mTvTitle;

            public MyViewHolder(@NonNull View itemView) {
                super(itemView);
                mTvTitle = itemView.findViewById(R.id.tv_title);
                mIvIcon = itemView.findViewById(R.id.iv_icon);
            }
        }
    }
}